<template>
  <div class="reportFormPage">
    <div class="report-dom">
      <el-row>
        <el-col :span="5" :offset="19">
          <div class="pageNumBox">
            <span>第</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.page }}&nbsp;</span>
            <span>页，共</span>
            <span class="placeholder-min text-center">&nbsp;{{ form.totalPage }}&nbsp;</span>
            <span>页</span>
          </div>
        </el-col>
      </el-row>
      <div class="topTwoBox">
        <div class="centerName">沥青混合料马歇尔试验检测报告(体积法)</div>
        <div class="codeText">
          <tr>
            BGLQ11005F
          </tr>
        </div>
      </div>
      <div class="threeTopBox">
        <div class="left-border">
          <div class="box-title">检测单位名称：</div>
          <div class>{{ form.jiancdwmc }}</div>
        </div>
        <div class="right-border">
          <span>报告编号：</span>
          <span v-if="isPdf" class="placeholder">{{ form.baogbh }}</span>
          <el-input class="code-input" v-else type="text" v-model="form.baogbh" @focus="handleFocus('baogbh')" />
        </div>
      </div>
      <div class="table-border">
        <!-- .........................1111111111111111111111111111111......................................................... -->
        <table height="220px" class="top-table">
          <tbody>
            <tr>
              <td height="30" align="center" width="15%">
                <span style="width: 90px; display: inline-block">施工/委托单位</span>
              </td>
              <td width="35%" bgcolor="#ffffff">
                <span>{{ form.shigwtdw }}</span>
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程名称</span>
              </td>
              <td bgcolor="#ffffff" width="35%">
                <span>{{ form.gongcmc }}</span>
              </td>
            </tr>
            <tr>
              <td height="30" align="center" width="15%">
                <span style="width: 90px; display: inline-block">工程部位/用途</span>
              </td>
              <td colspan="3">
                <span>{{ form.gongcbwyt }}</span>
              </td>
            </tr>
            <tr>
              <td height="50" align="center">样品信息</td>
              <td class="specimen-border" colspan="3">
                <span>样品名称：</span>
                <span :class="{ placeholder: !form.yangpmc }">{{ form.yangpmc }}</span>
                <span>；样品编号：</span>
                <span :class="{ 'placeholder-long': !form.yangpbh }">{{ form.yangpbh }}</span>
                <span>；样品数量：</span>
                <span :class="{ placeholder: !form.yangpsl }">{{ form.yangpsl }}</span>
                <span>；样品状态：</span>
                <span :class="{ placeholder: !form.yangpzt }">{{ form.yangpzt }}</span>
                <span>；来样时间：</span>
                <span :class="{ placeholder: !form.yangpsj }">{{ form.yangpsj }}</span>
              </td>
            </tr>
            <tr>
              <td height="50" align="center" width="15%">
                <span style="width: 90px; display: inline-block">检测依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.jiancyj }}</span>
                <el-input v-else type="textarea" v-model="form.jiancyj" :rows="2" class="mark" @dblclick.native="showBsJiancyjView" readonly />
              </td>
              <td align="center" width="15%">
                <span style="width: 90px; display: inline-block">判定依据</span>
              </td>
              <td width="35%">
                <span v-if="isPdf">{{ form.pandyj }}</span>
                <el-input v-else type="textarea" v-model="form.pandyj" :rows="2" @dblclick.native="showBsJudgeBaseView" @focus="handleFocus('pandyj')" class="mark" />
              </td>
            </tr>
            <tr class="bottom-border">
              <td height="50" align="center">
                <div>主要仪器设备</div>
                <div>名称及编号</div>
              </td>
              <td colspan="3">
                <span v-if="isPdf">{{ form.zhuyyqsbmcjbh }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.zhuyyqsbmcjbh" class="height100 width100 mark" @dblclick.native="showBsInstrumentView" readonly></el-input>
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .................................22222222222222222222222222222222............................................... -->
        <table height="616px" class="middle-table">
          <tbody>
            <tr height="25">
              <td>混合料类型</td>
              <td><el-input type="text" v-model="form.hunhllx" /></td>
              <td colspan="2">测定密度方法</td>
              <td><el-input type="text" v-model="form.cedmdff" /></td>
            </tr>
            <tr height="25">
              <td>标准试件尺寸(mm)</td>
              <td><el-input type="text" v-model="form.biaozsjcc" disabled /></td>
              <td colspan="2">击实次数</td>
              <td><el-input type="text" v-model="form.jiscs" disabled /></td>
            </tr>
            <tr height="25">
              <td width="15%">序号</td>
              <td width="35%">试验指标</td>
              <td width="15%">技术指标</td>
              <td width="15%">检测结果</td>
              <td width="20%">结果判定</td>
            </tr>
            <tr height="25">
              <td>1</td>
              <td>毛体积相对密度</td>
              <td><el-input type="text" v-model="form.baDetailVos[143].jiszb" class="mark" @dblclick.native="showBsJudgeBaseEditView('143')" readonly /></td>
              <td><el-input type="text" v-model="form.baDetailVos[143].jiancjg" disabled /></td>
              <td><el-input type="text" v-model="form.baDetailVos[143].jiegpd" disabled /></td>
            </tr>
            <tr height="25">
              <td>2</td>
              <td>空隙率VV %</td>
              <td><el-input type="text" v-model="form.baDetailVos[144].jiszb" class="mark" @dblclick.native="showBsJudgeBaseEditView('144')" readonly /></td>
              <td><el-input type="text" v-model="form.baDetailVos[144].jiancjg" disabled /></td>
              <td><el-input type="text" v-model="form.baDetailVos[144].jiegpd" disabled /></td>
            </tr>
            <tr height="25">
              <td>3</td>
              <td>间隙率VMA %</td>
              <td><el-input type="text" v-model="form.baDetailVos[145].jiszb" class="mark" @dblclick.native="showBsJudgeBaseEditView('145')" readonly /></td>
              <td><el-input type="text" v-model="form.baDetailVos[145].jiancjg" disabled /></td>
              <td><el-input type="text" v-model="form.baDetailVos[145].jiegpd" disabled /></td>
            </tr>
            <tr height="25">
              <td>4</td>
              <td>沥青饱和度VFA %</td>
              <td><el-input type="text" v-model="form.baDetailVos[146].jiszb" class="mark" @dblclick.native="showBsJudgeBaseEditView('146')" readonly /></td>
              <td><el-input type="text" v-model="form.baDetailVos[146].jiancjg" disabled /></td>
              <td><el-input type="text" v-model="form.baDetailVos[146].jiegpd" disabled /></td>
            </tr>
            <tr height="25">
              <td>5</td>
              <td>有效沥青体积百分率 %</td>
              <td><el-input type="text" v-model="form.baDetailVos[147].jiszb" class="mark" @dblclick.native="showBsJudgeBaseEditView('147')" readonly /></td>
              <td><el-input type="text" v-model="form.baDetailVos[147].jiancjg" disabled /></td>
              <td><el-input type="text" v-model="form.baDetailVos[147].jiegpd" disabled /></td>
            </tr>
            <tr height="25">
              <td>6</td>
              <td>稳定度MS kN</td>
              <td><el-input type="text" v-model="form.baDetailVos[148].jiszb" class="mark" @dblclick.native="showBsJudgeBaseEditView('148')" readonly /></td>
              <td><el-input type="text" v-model="form.baDetailVos[148].jiancjg" disabled /></td>
              <td><el-input type="text" v-model="form.baDetailVos[148].jiegpd" disabled /></td>
            </tr>
            <tr height="25">
              <td>7</td>
              <td>流值FL mm</td>
              <td><el-input type="text" v-model="form.baDetailVos[149].jiszb" class="mark" @dblclick.native="showBsJudgeBaseEditView('149')" readonly /></td>
              <td><el-input type="text" v-model="form.baDetailVos[149].jiancjg" disabled /></td>
              <td><el-input type="text" v-model="form.baDetailVos[149].jiegpd" disabled /></td>
            </tr>
            <tr height="25">
              <td>8</td>
              <td>粉胶比FB</td>
              <td><el-input type="text" v-model="form.baDetailVos[150].jiszb" class="mark" @dblclick.native="showBsJudgeBaseEditView('150')" readonly /></td>
              <td><el-input type="text" v-model="form.baDetailVos[150].jiancjg" disabled /></td>
              <td><el-input type="text" v-model="form.baDetailVos[150].jiegpd" disabled /></td>
            </tr>
            <tr height="25">
              <td>9</td>
              <td>沥青膜有效厚度DA μm</td>
              <td><el-input type="text" v-model="form.baDetailVos[151].jiszb" class="mark" @dblclick.native="showBsJudgeBaseEditView('151')" readonly /></td>
              <td><el-input type="text" v-model="form.baDetailVos[151].jiancjg" disabled /></td>
              <td><el-input type="text" v-model="form.baDetailVos[151].jiegpd" disabled /></td>
            </tr>
            <tr height="25">
              <td>10</td>
              <td>粗集料骨架间隙率VCAmix %</td>
              <td><el-input type="text" v-model="form.baDetailVos[152].jiszb" /></td>
              <td><el-input type="text" v-model="form.baDetailVos[152].jiancjg" disabled /></td>
              <td><el-input type="text" v-model="form.baDetailVos[152].jiegpd" disabled /></td>
            </tr>

            <tr>
              <td colspan="5" height="60px">
                <span v-if="isPdf" class="textarea-span">{{ form.jiancjl }}</span>
                <el-input v-else type="textarea" :rows="2" v-model="form.jiancjl" @focus="handleFocus('jiancjl')" @dblclick.native="getJcjl()" />
              </td>
            </tr>
          </tbody>
        </table>
        <!-- .....................................................33333333333333333................................................... -->
        <table height="60px" class="bottom-table">
          <tr>
            <td>
              <span v-if="isPdf" class="textarea-span">{{ form.fujsm }}</span>
              <el-input v-else type="textarea" :rows="2" v-model="form.fujsm" @focus="handleFocus('fujsm')" />
            </td>
          </tr>
        </table>
      </div>
      <!-- .................................44444444444............................................. -->
      <table height="22px" class="transparent">
        <tbody>
          <tr>
            <td width="10%" align="right">检测：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">审核：</td>
            <td width="15%" align="left"></td>
            <td width="10%" align="right">批准：</td>
            <td align="left" width="15%"></td>
            <td width="10%">日期：</td>
            <td align="left" width="15%">
              <div style="display: inline-block; margin-left: 20px">年</div>
              <div style="display: inline-block; margin-left: 20px">月</div>
              <div style="display: inline-block ;margin-left: 20px">日</div>
            </td>
          </tr>
        </tbody>
      </table>
    </div>
    <bs-instrument-view ref="bsInstrumentViewRef" @select="selectInstrument"></bs-instrument-view>
    <bs-jiancyj-view ref="bsJiancyjViewRef" @select="selectJiancyj" :syType="syType"></bs-jiancyj-view>
    <bs-judge-base-view ref="bsJudgeBaseViewRef" @select="selectJudge" :syType="syType"></bs-judge-base-view>
    <bs-judge-base-edit-view ref="bsJudgeBaseEditViewRef" @submit="selectJudgeBaseEdit" :syType="syType"></bs-judge-base-edit-view>
  </div>
</template>
<script>
import { handleFocus, emptyConvert, uniqueStr } from "@/views/reportForms/utils";
import { listLqhhlMxetjfbgBsInfo, getLqhhlMxetjfbgBsInfo, delLqhhlMxetjfbgBsInfo, addLqhhlMxetjfbgBsInfo, updateLqhhlMxetjfbgBsInfo, queryJcjl } from "@/api/report_lqhhl/lqhhlMxetjfbgBsInfo";
import BsJudgeBaseView from "@/views/sycs/bsJudgeBase/BsJudgeBaseView.vue";
import BsInstrumentView from "@/views/dept/bsInstrument/BsInstrumentView.vue";
import BsJiancyjView from "@/views/sycs/bsJiancyj/BsJiancyjView.vue";
import BsJudgeBaseEditView from "@/views/sycs/bsJudgeBase/BsJudgeBaseEditView.vue";
import decimal from "@/utils/big-decimal";
import Bus from "@/utils/bus";
import { computeBiQualification } from "@/api/sycs/biQualification";

export default {
  name: "lqhhlmxetjfbg",
  components: {
    BsJudgeBaseView,
    BsInstrumentView,
    BsJiancyjView,
    BsJudgeBaseEditView
  },
  props: {
    excelId: {
      type: [String, Number],
      default: () => ""
    },
    syType: {
      type: [String, Number],
      default: () => ""
    },
    page: {
      type: Number,
      default: () => 0
    },
    isPdf: {
      type: Boolean,
      default: () => false
    },
    printEmpty: {
      type: Boolean,
      default: () => false
    }
  },
  data() {
    return {
      params: {},
      query: {},
      // 表单参数
      form: {
        baDetailVos: {
          143: {},
          144: {},
          145: {},
          146: {},
          147: {},
          148: {},
          149: {},
          150: {},
          151: {},
          152: {}
        }
      },
      // 表单校验
      rules: {
        excelId: [{ required: true, message: "主键不能为空", trigger: "blur" }]
      }
    };
  },
  watch: {
    isPdf(newVal, oldVal) {
      this.form = { ...emptyConvert(this.form, newVal) };
    }
  },
  created() {
    this.getInfo();
  },
  mounted() {
    // 检测依据
    Bus.$on("setLqhhlmxetjfBgJiancyj", (data) => {
      const { jiancyj, jiancyjIds } = data;
      const str = jiancyj + (this.form.jiancyj ? "、" + this.form.jiancyj : "");
      const ids = jiancyjIds + (this.form.jiancyjIds ? "," + this.form.jiancyjIds : "");
      this.form.jiancyj = uniqueStr(str, "、");
      this.form.jiancyjIds = uniqueStr(ids, ",");
    });
    // 主要设备
    Bus.$on("setLqhhlmxetjfBgZhuyyqsbmcjbh", (data) => {
      const { zhuyyqsbmcjbh, shebIds } = data;
      const str = zhuyyqsbmcjbh + (this.form.zhuyyqsbmcjbh ? "、" + this.form.zhuyyqsbmcjbh : "");
      const ids = shebIds + (this.form.shebIds ? "," + this.form.shebIds : "");
      this.form.zhuyyqsbmcjbh = uniqueStr(str, "、");
      this.form.shebIds = uniqueStr(ids, ",");
    });
    Bus.$on("setLqhhlMxesyjcbgListTjf", (data) => {
      if (data.length <= 0) {
        return;
      }
      data.forEach((item) => {
        if (!this.form.baDetailVos[item.key] || !this.form.baDetailVos[item.key].qualId) {
          return;
        }
        this.form.baDetailVos[item.key].jiancjg = item.value;
      });
    });
    Bus.$on("setLqhhlMxesyjcbgTjf", (data) => {
      // this.form.hunhllx = data.hunhllx
      this.form.biaozsjcc = data.biaozsjcc;
      this.form.jiscs = data.jiscs;
      // this.form.hunhllx = data.hunhllx
    });
  },

  beforeDestroy() {
    // 或者你可以使用其他合适的生命周期钩子
    // 停止监听事件
    Bus.$off("setLqhhlMxesyjcbgTjf");
    Bus.$off("setLqhhlMxesyjcbgListTjf");
    Bus.$off("setLqhhlmxetjfBgJiancyj");
    Bus.$off("setLqhhlmxetjfBgZhuyyqsbmcjbh");
  },

  methods: {
    // 获取详情
    getInfo() {
      getLqhhlMxetjfbgBsInfo(this.excelId || this.$defaultExcelId).then((response) => {
        this.form = response.data;
        if (!this.form.jiancjl) {
          this.form.jiancjl = "检测结论：";
        }
        if (!this.form.fujsm) {
          this.form.fujsm = "附加声明：";
        }
      });
    },

    // 显示检测依据列表
    showBsJiancyjView() {
      this.$refs.bsJiancyjViewRef.init(this.form.jiancyjIds);
    },
    // 检测依据选择
    selectJiancyj(info) {
      this.form.jiancyj = info.label;
      this.form.jiancyjIds = info.ids;
    },

    // 显示判定依据列表
    showBsJudgeBaseView() {
      this.$refs.bsJudgeBaseViewRef.init(this.form.pandyjIds);
    },
    // 判断依据选择
    selectJudge(info) {
       this.form.pandyjIds = info.ids;
      this.form.pandyj = info.label;
    },

    // 显示仪器列表
    showBsInstrumentView() {
      this.$refs.bsInstrumentViewRef.init(this.form.shebIds);
    },
    // 仪器选择
    selectInstrument(info) {
      this.form.zhuyyqsbmcjbh = info.label;
      this.form.shebIds = info.ids;
    },

    // 获取检测结论
    getJcjl() {
      const form = JSON.parse(JSON.stringify(this.form));
      queryJcjl(emptyConvert(form)).then((res) => {
        const info = res.data;
        this.form.jiancjl = info.jiancjl;
      });
    },

    handleFocus(event) {
      handleFocus(event, this.page, this.form[event]);
    },
    submitForm() {
      return this.form;
    },
    // 显示单个技术编辑
    showBsJudgeBaseEditView(key) {
      const info = this.form.baDetailVos[key];
      info.refQualId = info.qualId;
      this.$refs.bsJudgeBaseEditViewRef.init(info);
    },
    // 编辑单个技术指标后赋值
    selectJudgeBaseEdit(info) {
      if (info.qualId) {
        this.form.baDetailVos[info.qualId] = info;
      }
      this.computeDetectionResult([info.qualId]);
    },
    // 计算检测结果
    computeDetectionResult(keys) {
      if (!keys || keys.length <= 0) {
        return;
      }
      const data = keys.map((key) => {
        const info = {
          ...this.form.baDetailVos[key],
          jiancjg: this.form.baDetailVos[key].jiancjg == "-" ? "" : this.form.baDetailVos[key].jiancjg
        };
        return info;
      });
      computeBiQualification(data).then((res) => {
        const returnData = res.data;
        returnData.forEach((item) => {
          item.jiancjg = item.jiancjg ? item.jiancjg : "-";
          this.form.baDetailVos[item.qualId] = item;
        });
      });
    }
  }
};
</script>

<style scoped>
</style>
